package com.training.hatton.base;

import org.json.JSONException;
import org.json.JSONObject;

public abstract class JSONModel {
	protected JSONObject jsonObject;

	public JSONModel(JSONObject object) {
		jsonObject = object;
	}
	public JSONModel(String source){
		try {
			jsonObject = new JSONObject(source);
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
	
	public String getJsonAsString(){
		return jsonObject.toString();
	}
	
	public String getString(String key) {
		try {
			return jsonObject.getString(key);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}
	public Long getLong(String key) {
		try {
			return jsonObject.getLong(key);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}
	public Boolean getBoolean(String key) {
		try {
			return jsonObject.getBoolean(key);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}
}
